package com.jt.tenant.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

@HttpInlet(Conn.INLET_USER_LOGIN)
public class GetLoginAdmin extends JTAsyGet<GetLoginAdmin.Info> {

    public String phone;

    public String password;

    public String type;

    public GetLoginAdmin(AsyCallBack asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        info.flag = body.optString("flag");

        if (info.msg.equals("000")&&info.flag.equals("0")) {

            JSONObject car = body.optJSONObject("car");

            info.userId = car.optString("userId");

            info.car_plateNum = car.optString("plateNum");

            info.car_vincode = car.optString("vinCode");

            info.city_code = car.optString("cityCode");

            info.engine_code = car.optString("engineCode");

            info.car_id = car.optString("id");

            info.city = car.optString("city");

            info.carId = car.optString("id");

            info.categoryId = car.optString("categoryId");

            info.carType = car.optString("carType");

            info.remark = car.optString("remark");

            info.pp = car.optString("pp");

            info.nk = car.optString("nk");

            info.pl = car.optString("pl");

            info.bsx = car.optString("mc");

            info.cx= car.optString("cx");

            JSONArray session = body.optJSONArray("session");

            for (int i = 0; i < session.length(); i++) {

                JSONObject object1 = session.optJSONObject(0);

                info.session_token = object1.optString("token");

            }

            JSONObject tUserSetting = body.optJSONObject("tUserSetting");

            for(int i = 1;i<7;i++){

                info.personSet.add(tUserSetting.optString("f"+String.valueOf(i)));

            }

            info.gpsType = body.optString("gpsType");

            info.baoxianFlag = body.optString("baoxianFlag");


//            用户信息
            JSONObject user = body.optJSONObject("user");

            info.user_phone = user.optString("phone");

            info.user_nickname = user.optString("nickname");

            info.user_headpic = user.optString("headpic");

            info.driverEffectiveDate = user.optString("driverEffectiveDate");

            info.driverNum = user.optString("driverNum");

            info.driverEffectiveYear = user.optString("driverEffectiveYear");

            info.user_sex = user.optString("sex");

            info.user_obdId = user.optString("obdId");

            info.user_integralCount = user.optString("integralCount");

            info.account_state = user.optString("tType");

            if(!user.optString("obdId").equals("")&&!user.optString("obdId").equals("null")) {

                JSONObject obd = body.optJSONObject("obd");

                info.wifi = obd.optString("wifiType");

                info.wifipwd = obd.optString("wifiPassword");

            }else {

                info.wifi = "";

                info.wifipwd = "";

            }

            info.tCollisionRemindValue = body.optString("tCollisionRemindValue");

            info.tCollisionRemindIsOpen = body.optString("tCollisionRemindIsOpen");

        }

        return info;

    }

    public static class Info {

        public String msg;

        public String flag;

        public String userId, car_plateNum, car_vincode, user_headpic, car_id,gpsType;

        public String session_token, session_user;

        public String user_phone, user_nickname, user_sex, user_obdId,user_integralCount;

        public String city_code, engine_code;

        public String account_state;//账号状态   0：未添加车辆，未绑定设备  1：已添加车辆，未绑定设备  2：已绑定设备

        public String carId, carType, categoryId, city, remark;

        public String pp,cx,pl,nk,bsx;

        public String driverEffectiveDate,driverNum,driverEffectiveYear;

        public String wifi,wifipwd;

        public String baoxianFlag;

        public String tCollisionRemindValue,tCollisionRemindIsOpen;

        public List<String> personSet = new ArrayList<>();

    }
}
